package com.jin.api.v1;

import com.jin.Exception.http.NotFoundException;
import com.jin.model.Activity;
import com.jin.service.ActivityService;
import com.jin.vo.ActivityCouponVo;
import com.jin.vo.ActivityPureVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("activity")
public class ActivityController {
    @Autowired
    ActivityService activityService;
    @GetMapping("/name/{name}")
    public ActivityPureVo getHomeActivity(@PathVariable String name){
        Activity activity = activityService.getByName(name);
        if (activity==null){
            new NotFoundException(40001);
        }
        ActivityPureVo vo = new ActivityPureVo(activity);
        return vo;
    }

    @GetMapping("/name/{name}/with_coupon")
    public ActivityCouponVo getActivityWithCoupons(@PathVariable String name){
        Activity activity = activityService.getByName(name);
        if (activity==null){
            new NotFoundException(40001);
        }
        ActivityCouponVo vo = new ActivityCouponVo(activity);
        return vo;
    }
}
